#pragma region Copyright
/// <copyright>
/// Copyright (c) 2007 Ilia Shramko.
/// Released under the terms of the GNU General Public License.
/// </copyright>
#pragma endregion

#include "stdafx.h"
//
//AllocatorPresenter::AllocatorPresenter() : CUnknown(NAME("Allocator Presenter"), NULL)
//{
//	ATLTRACE_TS(atlTraceOSHAP, TraceLevel::Info,
//		"AllocatorPresenter::AllocatorPresenter() : 0x%08X\r\n", this);
//}
//
//AllocatorPresenter::~AllocatorPresenter()
//{
//	ATLTRACE_TS(atlTraceOSHAP, TraceLevel::Info,
//		"AllocatorPresenter::~AllocatorPresenter() : 0x%08X\r\n", this);
//}
//
//HRESULT AllocatorPresenter::Initialize(IBaseFilter* vmr)
//{
//	if(vmr == NULL) return E_INVALIDARG;
//
//	HRESULT hr = S_OK;
//
//	CComPtr<IVMRSurfaceAllocator> vmrSA;
//	hr = vmrSA.CoCreateInstance(CLSID_AllocPresenter, NULL, CLSCTX_INPROC_SERVER);
//
//	//hr = vmr->QueryInterface(&vmrSA);
//	ATLASSERT(SUCCEEDED(hr));
//	if(FAILED(hr)) return hr;
//
//	CComPtr<IVMRImagePresenter> vmrIP;
//	hr = vmrSA->QueryInterface(&vmrIP);
//	ATLASSERT(SUCCEEDED(hr));
//	if(FAILED(hr)) return hr;
//
//	CComPtr<IVMRSurfaceAllocatorNotify> vmrSAN;
//	hr = vmr->QueryInterface(&vmrSAN);
//	ATLASSERT(SUCCEEDED(hr));
//	if(FAILED(hr)) return hr;
//
//	_defaultSA = vmrSA; // This interface is required in AdviseNotify method
//	_defaultIP = vmrIP;
//	hr = vmrSAN->AdviseSurfaceAllocator((DWORD_PTR)UserID, static_cast<IVMRSurfaceAllocator*>(this));
//	ATLASSERT(SUCCEEDED(hr));
//	if(FAILED(hr))
//	{
//		_defaultSA = NULL;
//		_defaultIP = NULL;
//		return hr;
//	}
//
//	return hr;
//}
//
//STDMETHODIMP AllocatorPresenter::NonDelegatingQueryInterface(REFIID riid, void** ppv)
//{
//	if(riid == IID_IVMRSurfaceAllocator)
//		return GetInterface((IVMRSurfaceAllocator*)this, ppv);
//	else if(riid == IID_IVMRImagePresenter)
//		return GetInterface((IVMRImagePresenter*)this, ppv);
//
//	return CUnknown::NonDelegatingQueryInterface(riid,ppv);
//}
//
////
//// IVMRSurfaceAllocator
////
//
//STDMETHODIMP AllocatorPresenter::AllocateSurface(DWORD_PTR dwUserID,
//	VMRALLOCATIONINFO* lpAllocInfo, DWORD* lpdwBuffer, LPDIRECTDRAWSURFACE7* lplpSurface)
//{
//	if(_defaultSA)
//		return _defaultSA->AllocateSurface(dwUserID, lpAllocInfo, lpdwBuffer, lplpSurface);
//	else
//		return E_POINTER;
//}
//
//
//STDMETHODIMP AllocatorPresenter::FreeSurface(DWORD_PTR dwUserID)
//{
//	if(_defaultSA)
//		return _defaultSA->FreeSurface(dwUserID);
//	else
//		return E_POINTER;
//}
//
//
//STDMETHODIMP AllocatorPresenter::PrepareSurface(DWORD_PTR dwUserID,
//	LPDIRECTDRAWSURFACE7 lplpSurface, DWORD dwSurfaceFlags)
//{
//	if(_defaultSA)
//		return _defaultSA->PrepareSurface(dwUserID, lplpSurface, dwSurfaceFlags);
//	else
//		return E_POINTER;
//}
//
///// <summary>
///// The AdviseNotify method is called by the VMR to provide the allocator-presenter
////  with an interface pointer for notification callbacks.
///// </summary>
//STDMETHODIMP AllocatorPresenter::AdviseNotify(IVMRSurfaceAllocatorNotify* lpIVMRSurfAllocNotify)
//{
//	_defaultSAN = lpIVMRSurfAllocNotify;
//	if(_defaultSA)
//		return _defaultSA->AdviseNotify(static_cast<IVMRSurfaceAllocatorNotify*>(this));
//	else
//		return E_POINTER;
//}
//
//
////
//// IVMRSurfaceAllocatorNotify
////
//// Default allocator-presenter uses this interface to inform the VMR-7 of changes
//// to the system environment that affect the DirectDraw surfaces. 
////
//
//
//STDMETHODIMP AllocatorPresenter::AdviseSurfaceAllocator(
//	DWORD_PTR dwUserID, IVMRSurfaceAllocator* lpIVRMSurfaceAllocator)
//{
//	if(_defaultSAN)
//		return _defaultSAN->AdviseSurfaceAllocator(dwUserID, lpIVRMSurfaceAllocator);
//	else
//		return E_POINTER;
//}
//
//
//STDMETHODIMP AllocatorPresenter::SetDDrawDevice(LPDIRECTDRAW7 lpDDrawDevice, HMONITOR hMonitor)
//{
//	if(_defaultSAN)
//		return _defaultSAN->SetDDrawDevice(lpDDrawDevice, hMonitor);
//	else
//		return E_POINTER;
//}
//
//
//STDMETHODIMP AllocatorPresenter::ChangeDDrawDevice(LPDIRECTDRAW7 lpDDrawDevice, HMONITOR hMonitor)
//{
//	if(_defaultSAN)
//		return _defaultSAN->ChangeDDrawDevice(lpDDrawDevice, hMonitor);
//	else
//		return E_POINTER;
//}
//
//
//STDMETHODIMP AllocatorPresenter::RestoreDDrawSurfaces()
//{
//	if(_defaultSAN)
//		return _defaultSAN->RestoreDDrawSurfaces();
//	else
//		return E_POINTER;
//}
//
//
//STDMETHODIMP AllocatorPresenter::NotifyEvent(LONG EventCode, LONG_PTR lp1, LONG_PTR lp2)
//{
//	if(_defaultSAN)
//		return _defaultSAN->NotifyEvent(EventCode, lp1, lp2);
//	else
//		return E_POINTER;
//}
//
//
//STDMETHODIMP AllocatorPresenter::SetBorderColor(COLORREF clr)
//{
//	if(_defaultSAN)
//		return _defaultSAN->SetBorderColor(clr);
//	else
//		return E_POINTER;
//}
//
//
//
////
//// IVMRImagePresenter
////
//
//STDMETHODIMP AllocatorPresenter::StartPresenting(DWORD_PTR dwUserID)
//{
//	if(_defaultIP)
//		return _defaultIP->StartPresenting(dwUserID);
//	else
//		return E_POINTER;
//}
//
//
//STDMETHODIMP AllocatorPresenter::StopPresenting(DWORD_PTR dwUserID)
//{
//	if(_defaultIP)
//		return _defaultIP->StopPresenting(dwUserID);
//	else
//		return E_POINTER;
//}
//
//
//STDMETHODIMP AllocatorPresenter::PresentImage(DWORD_PTR dwUserID, VMRPRESENTATIONINFO* lpPresInfo)
//{
//	if(_defaultIP)
//		return _defaultIP->PresentImage(dwUserID, lpPresInfo);
//	else
//		return E_POINTER;
//}













